{% extends "forums/base.html" %}
{% from "layout/errorlist.html" import errorlist %}
{% from "includes/common_macros.html" import content_editor with context %}
{# L10n: {f} if the name of the forum. #}
{% set title = _('Create a new thread | {f} | Forums')|f(f=forum.name) %}
{% set crumbs = [(url('forums.forums'), _('Forums')),
(url('forums.threads', forum.slug), forum.name),
(None, _('Create a new thread'))] %}
{% set styles = ('forums', 'jqueryui') %}
{% set scripts = ('forums', 'jqueryui') %}

{% block content %}
  <div id="new-thread" class="grid_12">
    <h1>{{ _('Create a new thread') }}</h1>

    <form action="{{ url('forums.new_thread', forum.slug) }}" method="post" class="new-thread">
      {% csrf_token %}
      {{ errorlist(form) }}

      {% if request.limited %}
        <div class="warning-box">
          {{ _('You have exceeded the number of threads and replies that can be posted in a given amount of time. Please try again shortly.') }}
        </div>
      {% endif %}

      {% for field in form %}
        <div class="form-widget{% if field.errors %} invalid{% endif %}">
          {{ field.label_tag()|safe }}
          {% if field.name == 'content' %}
            <div class="content-box">
              {{ content_editor(field) }}
            </div>
          {% else %}
            {{ field|safe }}
          {% endif %}
        </div>
      {% endfor %}

      <div class="form-widget submit">
        <button type="submit" class="btn btn-submit big">{{ _('Post Thread') }}</button>
        <button type="submit" class="btn" id="preview" name="preview"
                data-preview-url="{{ url('forums.post_preview_async') }}"
                data-preview-container-id="post-preview"
                data-preview-content-id="id_content">{{ _('Preview') }}
        </button>
        <a class="btn" href="{{ url('forums.threads', forum.slug) }}">{{ _('Cancel') }}</a>
      </div>

      <div id="post-preview">
        {% if post_preview %}
          {% include "forums/includes/post_preview.html" %}
        {% endif %}
      </div>
    </form>
  </div>
{% endblock %}
